package com.example.apiinterface.controller;

import com.example.apiinterfacesdk.model.User;
import com.example.apiinterfacesdk.utils.SignUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/get")
    public String getNameByGET( String name){
        return  "GET 你的名字是"+name;
    }

    @PostMapping("/post")
    public String getNameByPOST(@RequestParam String name){
        return "POST 你的名字是"+name;
    }

    @PostMapping("/user")
    public String getUserNameByPOST(@RequestBody User username, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String timestamp = request.getHeader("timestamp");
//        String sign = request.getHeader("sign");
//        String body = request.getHeader("body");
//        if (!accessKey.equals("admin")){
//            throw new RuntimeException("无权限");
//        }
//        if (Long.parseLong(nonce)>10000){
//            throw new RuntimeException("无权限");
//        }
//        String serverSign = SignUtils.genSign(body, "admin");
//        if(!sign.equals(serverSign)){
//            throw new RuntimeException("无权限");
//        }
//        long currentTime = System.currentTimeMillis() / 1000;
//        if (currentTime-Long.parseLong(timestamp)>=5*60L){
//            throw new RuntimeException("请求超时");
//        }

        return "POST 用户的名字是"+username;
    }
}
